package com.wz.project.bas.fw.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.bas.fw.domain.BasBarcodeFw;
import com.wz.project.bas.fw.service.IBasBarcodeFwService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 防伪检验Controller
 * 
 * @author wz
 * @date 2022-10-18
 */
@Controller
@RequestMapping("/bas/fw")
public class BasBarcodeFwController extends BaseController
{
    private String prefix = "bas/fw";

    @Autowired
    private IBasBarcodeFwService basBarcodeFwService;

    @RequiresPermissions("bas:fw:view")
    @GetMapping()
    public String fw()
    {
        return prefix + "/fw";
    }

    /**
     * 查询防伪检验列表
     */
//    @RequiresPermissions("bas:fw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasBarcodeFw basBarcodeFw)
    {
        startPage();
        List<BasBarcodeFw> list = basBarcodeFwService.selectBasBarcodeFwList(basBarcodeFw);
        return getDataTable(list);
    }

    /**
     * 导出防伪检验列表
     */
    @RequiresPermissions("bas:fw:export")
    @Log(title = "防伪检验", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasBarcodeFw basBarcodeFw)
    {
        List<BasBarcodeFw> list = basBarcodeFwService.selectBasBarcodeFwList(basBarcodeFw);
        ExcelUtil<BasBarcodeFw> util = new ExcelUtil<BasBarcodeFw>(BasBarcodeFw.class);
        return util.exportExcel(list, "fw");
    }

    /**
     * 新增防伪检验
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存防伪检验
     */
    @RequiresPermissions("bas:fw:add")
    @Log(title = "防伪检验", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasBarcodeFw basBarcodeFw)
    {
        String uid = UUID.randomUUID().toString();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        basBarcodeFw.setId(uid);
        basBarcodeFw.setTime(simpleDateFormat.format(new Date()));
        return toAjax(basBarcodeFwService.insertBasBarcodeFw(basBarcodeFw));
    }

    /**
     * 修改防伪检验
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasBarcodeFw basBarcodeFw = basBarcodeFwService.selectBasBarcodeFwById(id);
        mmap.put("basBarcodeFw", basBarcodeFw);
        return prefix + "/edit";
    }

    /**
     * 修改保存防伪检验
     */
    @RequiresPermissions("bas:fw:edit")
    @Log(title = "防伪检验", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasBarcodeFw basBarcodeFw)
    {
        return toAjax(basBarcodeFwService.updateBasBarcodeFw(basBarcodeFw));
    }

    /**
     * 删除防伪检验
     */
    @RequiresPermissions("bas:fw:remove")
    @Log(title = "防伪检验", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basBarcodeFwService.deleteBasBarcodeFwByIds(ids));
    }
}
